import Vue from 'vue'
import store from './store'
import '@/assets/less/index.less'
import type { CreateElement } from 'vue'
import GlobalMixin from '@/mixins/GlobalMixin'
import GEmpty from './components/GEmpty.vue'
import Taro from '@tarojs/taro'
Vue.prototype.$platform = process.env.TARO_ENV
Vue.mixin(GlobalMixin)
Vue.component(GEmpty.name, GEmpty)
// @ts-ignore
Taro.options.html.transformElement = (el) => {
  console.log('html===', el)
  if (el.nodeName === 'image') {
    el.setAttribute('mode', 'widthFix')
  } else if (el.h5tagName === 'a' && el.getAttribute('href')) {
    el.nodeName = 'navigator'
    el.setAttribute('open-type', 'navigate')
    el.setAttribute('url', '/pages/webview/index?src=' + encodeURIComponent(el.getAttribute('href')))
  } else if (el.h5tagName === 'span') {
    el.nodeName = 'view'
  } else if (el.nodeName === 'video') {
    el.setAttribute('direction', 90)
  }
  return el
}

const App = {
  store,
  onShow() {
    // console.log('App onShow')
  },
  onHide() {
    // console.log('App onHide')
  },
  onLaunch() {
    const system = Taro.getSystemInfoSync()
    this.$store.commit('setSystem', system)
    // 应用启用时触发，只会触发一次
  },
  render(h: CreateElement) {
    // this.$slots.default 是将要会渲染的页面
    return h('div', { class: { taro_router: true } }, this.$slots.default)
  }
}

export default App

